package keeto.com.vn.classified.utils;

import java.util.HashMap;
import java.util.Hashtable;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
 * @author 陆扬 washpan
 * @category 获取设备信息的工具类
 * */
public class DeviceInfoUtil {
	/**
	 * @category 国家代码键值 Country code key value
	 * */
	public static final String KEY_COUNTRY_CODE_ISO = "NetworkCountryIso";

	/**
	 * @category 获取国家代码 get country code
	 * */
	public static String getCountryCode(Context context) {

		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		String iso =  tm.getSimCountryIso() == null ? "" : tm
				.getSimCountryIso();
		return existCountryCode(iso);
	}
	
	private static String existCountryCode(String key){
		HashMap<String, String> mapping = new HashMap<String, String>();
		//TEST CODE
		mapping.put("us", "+86");
		mapping.put("cn", "+86");
		mapping.put("sg", "+65");
		return mapping.get(key);
		
	}

	/**
	 * @return Device Information
	 */
	public static Hashtable<String, Object> getDeviceInfo(Context context) {

		Hashtable<String, Object> table = new Hashtable<String, Object>();
		table.put("PRODUCT", android.os.Build.PRODUCT);
		table.put("TAGS", android.os.Build.TAGS);
		table.put("VERSION_CODES.BASE: ", android.os.Build.VERSION_CODES.BASE);
		table.put("MODEL", android.os.Build.MODEL);
		table.put("SDK", android.os.Build.VERSION.SDK);
//		table.put("VERSION.RELEASE", android.os.Build.VERSION.RELEASE);
//		table.put("DEVICE", android.os.Build.DEVICE);
//		table.put("DISPLAY", android.os.Build.DISPLAY);
//		table.put("BRAND", android.os.Build.BRAND);
//		table.put("BOARD", android.os.Build.BOARD);
//		table.put("ID", android.os.Build.ID);
//		table.put("MANUFACTURER", android.os.Build.MANUFACTURER);
//		table.put("USER", android.os.Build.USER);
//		TelephonyManager tm = (TelephonyManager) context
//				.getSystemService(Context.TELEPHONY_SERVICE);
//		table.put("DeviceId(IMEI)",
//				tm.getDeviceId() == null ? "" : tm.getDeviceId());
//		table.put(
//				"DeviceSoftwareVersion",
//				tm.getDeviceSoftwareVersion() == null ? "" : tm
//						.getDeviceSoftwareVersion());
//		table.put("Line1Number",
//				tm.getLine1Number() == null ? "" : tm.getLine1Number());
//		table.put(KEY_COUNTRY_CODE_ISO, tm.getNetworkCountryIso() == null ? ""
//				: tm.getNetworkCountryIso());
//		table.put("NetworkOperator",
//				tm.getNetworkOperator() == null ? "" : tm.getNetworkOperator());
//		table.put(
//				"NetworkOperatorName",
//				tm.getNetworkOperatorName() == null ? "" : tm
//						.getNetworkOperatorName());
//		table.put("NetworkType", tm.getNetworkType());
//		table.put("PhoneType", tm.getPhoneType());
//		table.put("SimCountryIso",
//				tm.getSimCountryIso() == null ? "" : tm.getSimCountryIso());
//		table.put("SimOperator",
//				tm.getSimOperator() == null ? "" : tm.getSimOperator());
//		table.put("SimOperatorName",
//				tm.getSimOperatorName() == null ? "" : tm.getSimOperatorName());
//		table.put("SimSerialNumber",
//				tm.getSimSerialNumber() == null ? "" : tm.getSimSerialNumber());
//		table.put("SimState", tm.getSimState());
//		table.put("SubscriberId(IMSI)",
//				tm.getSubscriberId() == null ? "" : tm.getSubscriberId());
		Log.i("ExceptionHandler", "extraInfo:" + table);
		return table;
	}
}
